package systeminfo

import (
	"fmt"
	"syscall"
	"time"
)

type Data struct {
	Uptime string `json:"uptime"`
	Ram    Ram    `json:"ram"`
	Cpu    Cpu    `json:"cpu"`
	Hdd    []Hdd  `json:"hdd"`
}

type Ram struct {
	Totalram  string `json:"totalram"`
	Freeram   string `json:"freeram"`
	Totalswap string `json:"totalswap"`
	Freeswap  string `json:"freeswap"`
}

type Cpu struct {
	CpuUsage string `json:"cpuusage"`
	Busy     string `json:"busy"`
	Total    string `json:"total"`
}

type Hdd struct {
	Path string `json:"path"`
	All  string `json:"allhdd"`
	Used string `json:"usedhdd"`
	Free string `json:"freehdd"`
}

func getUptime() string {
	// Переделать показывает не верное время.
	info := syscall.Sysinfo_t{}
	err := syscall.Sysinfo(&info)
	if err != nil {
		fmt.Println("Error:", err)
	}
	//uptime seconds since boot
	t := time.Unix(info.Uptime, 0)
	uptime := t.Format("15:04:05 2006-01-02")

	return fmt.Sprintf(uptime)

}

func GetSensorsData() (data Data) {
	data.Uptime = getUptime()
	data.Cpu = GetCpuStatus()
	data.Hdd = GetHDDStatus()
	data.Ram = GetRamStatus()
	return
}
